package com.fmdj.odr.controller;

import cn.hutool.core.bean.BeanUtil;
import com.fmdj.common.util.CommonResult;
import com.fmdj.odr.controller.form.InsertCommentForm;
import com.fmdj.odr.controller.form.SearchCommentByOrderIdForm;
import com.fmdj.odr.controller.form.UpdateBillFeeForm;
import com.fmdj.odr.db.pojo.OrderCommentEntity;
import com.fmdj.odr.service.OrderCommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/comment")
@Tag(name = "OrderCommentController", description = "订单评论模块web接口")
@Slf4j
public class OrderCommentController {

    @Autowired
    private OrderCommentService orderCommentService;

    @PostMapping("/insertComment")
    @Operation(summary = "更新账单(同时更新订单以及插入一条分账记录)")
    public CommonResult insertComment(@RequestBody @Valid InsertCommentForm form) {
        OrderCommentEntity entity = BeanUtil.toBean(form, OrderCommentEntity.class);
        entity.setStatus((byte)1);
        entity.setCreateTime(new Date()); //当前时间
        int rows = orderCommentService.insertComment(entity);
        return CommonResult.ok().put(CommonResult.RETURN_ROW, rows);
    }

    @PostMapping("/searchCommentByOrderId")
    @Operation(summary = "根据订单id查询评价")
    public CommonResult searchCommentByOrderId(@RequestBody @Valid SearchCommentByOrderIdForm form) {
        Map map = BeanUtil.beanToMap(form);
        HashMap hashMap = orderCommentService.searchCommentByOrderId(map);
        return CommonResult.ok().put(CommonResult.RETURN_RESULT, hashMap);
    }

}
